//
//  HWwenzipinglunViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2021/9/1.
//  Copyright © 2021 Chendaobin. All rights reserved.
//

#import "HWwenzipinglunViewController.h"
#import "LFOpinionView.h"
#import "HWLoginController.h"
@interface HWwenzipinglunViewController ()

@property (nonatomic, strong) LFOpinionView *textView; 
@end

@implementation HWwenzipinglunViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavigionview];
    
    [self setupUI];
    
    
}



-(void)setupUI {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    UITapGestureRecognizer *tap10 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shituxianshi)];
    
    [self.view addGestureRecognizer:tap10];
    
    
    
    
    _textView = [[LFOpinionView alloc] init];
    _textView.alwaysBounceVertical = YES;
    _textView.delegate = self;
    //     _textView.x = 10;
    //     _textView.y = 0;
    _textView.frame = CGRectMake(20, CF_NavHeight +10, kScreenW- 40, 150);
    _textView.backgroundColor = [UIColor whiteColor];
    _textView.backgroundColor = RGB(245, 245, 245);
    _textView.textColor = RGB(51, 51, 51);
    _textView.placeholder = @"你可以从玩法、画质、福利、氪金性价比等方面分享～";
    _textView.font = [UIFont systemFontOfSize:12];
    _textView.layer.cornerRadius =10 ;
    _textView.layer.masksToBounds = YES;
    [self.view addSubview:_textView];
    
    
    
}


- (void)shituxianshi {
    
  
    [self.view endEditing:YES];
    
    
    
    
}



// 评价界面
- (void)setupNavigionview {

    self.navigationItem.title = @"评价";
    self.view.backgroundColor = RGB(245, 245, 245);
    UIButton *fabuBut = [UIButton buttonWithType:UIButtonTypeCustom];
    fabuBut.frame = CGRectMake(0, 0, 50, 26);
    fabuBut.backgroundColor = RGB(247, 124, 47);
    [fabuBut setTitle:@"发表" forState:UIControlStateNormal];
    [fabuBut setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    fabuBut.layer.cornerRadius = 2;
    fabuBut.layer.masksToBounds = YES;
    [fabuBut  addTarget:self action:@selector(fabuButTap) forControlEvents:UIControlEventTouchUpInside];
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:fabuBut];
    
    
    
}

// 发布按钮
- (void)fabuButTap {
    
   //  [self shujushanchuantupian];
    
    if (!(_textView.text.length > 0)) {
      
        [MBProgressHUD showError:@"请输入内容"];
        return;
        
    }
    
    
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
        
        HWLoginController *login = [[HWLoginController alloc]init];
        [self.navigationController pushViewController:login animated:YES];
       //  [self weidengluqingqiu];
        
        return ;
        
    }
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    int t = [WMUtil getRandomNumber:101 to:998];
    NSString *tStr = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    


    
    NSDictionary *parametes = @{
                                @"ct" : @"app2021",
                                @"ac" : @"gameinfo_pinglun",
                                @"ios" : @"1",
                                @"id" :self.gameIDStr,
                                @"uid" :userID,
                                @"t" :tStr,
                                @"sign":signMD5,
                                @"content": _textView.text,
                                @"pid":self.pid,
                                @"ppid":@"0",
                              
                                };
    
    if (self.ppid != nil ) {
           parametes = @{
                                    @"ct" : @"app2021",
                                    @"ac" : @"gameinfo_pinglun",
                                    @"ios" : @"1",
                                    @"id" :self.gameIDStr,
                                    @"uid" :userID,
                                    @"t" :tStr,
                                    @"sign":signMD5,
                                    @"content": _textView.text,
                                    @"pid":self.pid,
                                    @"ppid":self.ppid,
                                  
                                    };
    }
    
    
     //  @"images" :ico,
    
    [MBProgressHUD showMessage:@"正在发表...."];
    [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          //   [MBProgressHUD hideHUD];
             
             
             if ([codeStr intValue] == 1) {
                 [self.navigationController popViewControllerAnimated:YES];
                 [MBProgressHUD  showError:@"发表评论成功"];
    

             } else {
                 
                  [MBProgressHUD  showError:response[@"message"]];
                 
             }
             NSLog(@"%@",response);
        
    } failure:^(NSString *error) {
         [MBProgressHUD  showError:@"加载失败"];
 
    }];
 
    
}

@end
